package org.zhu.util;


import net.coobird.thumbnailator.Thumbnails;


import java.io.*;

/**
 * Created by zhu yingzhi on 2017/9/12.
 */
public class ImageUtil {
    public static void main(String[] args) throws IOException {
        // 1 对图片指定比例压缩
        ImageUtil thumbnailatorTest = new ImageUtil();
        thumbnailatorTest.changeImgSize();

    }

    /**
     * 按原来的比例缩放
     * 若图片横比width小，高比height小，不变 若图片横比width小，高比height大，高缩小到height，图片比例不变
     * 若图片横比width大，高比height小，横缩小到width，图片比例不变
     * 若图片横比width大，高比height大，图片按比例缩小，横为width或高为height
     *
     * @throws IOException
     */
    public void changeImgSizeRatio() throws IOException {
        String result = "F:\\";
        Thumbnails.of(result + "timg.jpg").size(200, 300).toFile(result + "timg213.jpg");
    }

    /**
     * 按指定尺寸强制缩放
     *
     * @throws IOException
     */
    public void changeImgSize() throws IOException {
        String result = "F:\\";
        Thumbnails.of(result + "timg.jpg").size(200, 300).keepAspectRatio(false).toFile(result + "timg213.jpg");
    }


}
